package com.ithong.drug.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ithong.drug.entity.DrugInfo;
import com.ithong.drug.mapper.DrugInfoMapper;
import com.ithong.drug.service.DrugInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thymeleaf.util.StringUtils;

import java.util.List;

@Service
public class DrugInfoServiceImpl extends ServiceImpl<DrugInfoMapper, DrugInfo> implements DrugInfoService {

    @Autowired
    private DrugInfoMapper drugInfoMapper;

    @Override
    public IPage<DrugInfo> selectDrugInfoPage(int pageNum, int pageSize, String param) {
        QueryWrapper<DrugInfo> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(param)){
            wrapper.like("name",param);
        }
        Page<DrugInfo> page = new Page<>(pageNum,pageSize);
        return drugInfoMapper.selectPage(page,wrapper);
    }

    @Override
    public int addDrugInfo(DrugInfo drugInfo) {
        return drugInfoMapper.insert(drugInfo);
    }

    @Override
    public int editDrugInfo(DrugInfo drugInfo) {
        return drugInfoMapper.updateById(drugInfo);
    }

    @Override
    public DrugInfo queryDrugInfoById(Integer id) {
        return drugInfoMapper.selectById(id);
    }

    @Override
    public int delDrugInfo(Integer id) {
        return drugInfoMapper.deleteById(id);
    }

    @Override
    public List<DrugInfo> queryDrugInfoList() {
        return drugInfoMapper.selectList(null);
    }
}
